<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>nrf51/Board/nrf6310/ext_sensors/cherry8x16_example/main.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="alias.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="alias.js"></script>

<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>


<script type="text/javascript">
  jQuery(document).ready(function () {
    if(gref){ // Number all _img and _table classes
      gref();
    }
  });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nRF51 General Code Examples
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('nrf6310_2ext__sensors_2cherry8x16__example_2main_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">nrf51/Board/nrf6310/ext_sensors/cherry8x16_example/main.c</div>  </div>
</div>
<div class="contents">
<a href="nrf6310_2ext__sensors_2cherry8x16__example_2main_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.</span>
<a name="l00002"></a>00002 <span class="comment"> *</span>
<a name="l00003"></a>00003 <span class="comment"> * The information contained herein is confidential property of Nordic</span>
<a name="l00004"></a>00004 <span class="comment"> * Semiconductor ASA.Terms and conditions of usage are described in detail</span>
<a name="l00005"></a>00005 <span class="comment"> * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> * Licensees are granted free, non-transferable use of the information. NO</span>
<a name="l00008"></a>00008 <span class="comment"> * WARRANTY of ANY KIND is provided. This heading must NOT be removed from</span>
<a name="l00009"></a>00009 <span class="comment"> * the file.</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> */</span>
<a name="l00012"></a>00012 
<a name="l00038"></a>00038 <span class="preprocessor">#include &lt;stdbool.h&gt;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &lt;stdint.h&gt;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &quot;<a class="code" href="cherry8x16_8h.html" title="Cherry 8x16 keyboard matrix driver.">cherry8x16.h</a>&quot;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &quot;nrf_delay.h&quot;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &quot;<a class="code" href="simple__uart_8h.html" title="Simple UART driver.">simple_uart.h</a>&quot;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &quot;nrf_gpio.h&quot;</span>
<a name="l00044"></a>00044 
<a name="l00045"></a>00045 <span class="preprocessor">#define USE_UART // Comment out to use pins 8-15 for LEDs. Otherwise UART will be used to transmit keystrokes.</span>
<a name="l00046"></a>00046 <span class="preprocessor"></span>
<a name="l00050"></a><a class="code" href="group__cherry8x16__example.html#gafb80f61fa944be28d9895a47602e8957">00050</a> <span class="preprocessor">#define SIMPLE_UART_TXD_PIN_NUMBER (24U)</span>
<a name="l00051"></a>00051 <span class="preprocessor"></span>
<a name="l00055"></a><a class="code" href="group__cherry8x16__example.html#ga93d696b159f34e012cf60f3c2e2050be">00055</a> <span class="preprocessor">#define SIMPLE_UART_RXD_PIN_NUMBER (25U)</span>
<a name="l00056"></a>00056 <span class="preprocessor"></span>
<a name="l00060"></a><a class="code" href="group__cherry8x16__example.html#ga7b0771426bcb19acdebee8b36aed8824">00060</a> <span class="keyword">static</span> <span class="keyword">const</span> uint8_t <span class="keyword">volatile</span> * <span class="keyword">const</span> <a class="code" href="group__cherry8x16__example.html#ga7b0771426bcb19acdebee8b36aed8824">matrix_row_port</a> = ((uint8_t*)(&amp;NRF_GPIO-&gt;IN)) + 2;
<a name="l00061"></a>00061 
<a name="l00065"></a><a class="code" href="group__cherry8x16__example.html#ga2d1e718ed363e61cd45e390db88f79b8">00065</a> <span class="keyword">static</span> uint16_t * <span class="keyword">const</span> <a class="code" href="group__cherry8x16__example.html#ga2d1e718ed363e61cd45e390db88f79b8">matrix_column_port</a> = ((uint16_t*)(&amp;NRF_GPIO-&gt;OUT));
<a name="l00066"></a>00066 
<a name="l00067"></a><a class="code" href="group__cherry8x16__example.html#ga3375613e875ab025e3ff7441cea933cf">00067</a> <span class="preprocessor">#define KEYPAD_NUM_OF_COLUMNS 16 //!&lt; Number of columns in the keyboard matrix</span>
<a name="l00068"></a><a class="code" href="group__cherry8x16__example.html#ga3dd1faa92e9de0dc3858af5f114d1c38">00068</a> <span class="preprocessor"></span><span class="preprocessor">#define KEYPAD_NUM_OF_ROWS 8 //!&lt; Number of rows in the keyboard matrix</span>
<a name="l00069"></a>00069 <span class="preprocessor"></span>
<a name="l00070"></a>00070 <span class="preprocessor">#ifdef USE_UART</span>
<a name="l00071"></a>00071 <span class="preprocessor"></span>
<a name="l00075"></a><a class="code" href="group__cherry8x16__example.html#ga144e0104b848cd4ac9000417a855d530">00075</a> <span class="keyword">static</span> <span class="keyword">const</span> uint8_t <a class="code" href="group__cherry8x16__example.html#ga144e0104b848cd4ac9000417a855d530">usb_hid2_ascii_look_up</a>[<a class="code" href="group__cherry8x16__example.html#ga3375613e875ab025e3ff7441cea933cf" title="Number of columns in the keyboard matrix.">KEYPAD_NUM_OF_COLUMNS</a>*<a class="code" href="group__cherry8x16__example.html#ga3dd1faa92e9de0dc3858af5f114d1c38" title="Number of rows in the keyboard matrix.">KEYPAD_NUM_OF_ROWS</a>] =
<a name="l00076"></a>00076 {
<a name="l00077"></a>00077   0x00, 0x00, 0x00, 0x00, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
<a name="l00078"></a>00078   0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
<a name="l00079"></a>00079   0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A,
<a name="l00080"></a>00080   0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30,
<a name="l00081"></a>00081   0x0D, 0x1B, 0x08, 0x09, 0x20, 0x2D, 0x3D, 0x5B, 0x5D, 0x00,
<a name="l00082"></a>00082   0x00, 0x3B, 0x27, 0x00, 0x2C, 0x2E, 0x2F, 0x00, 0x00, 0x00,
<a name="l00083"></a>00083   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
<a name="l00084"></a>00084   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
<a name="l00085"></a>00085   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
<a name="l00086"></a>00086   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
<a name="l00087"></a>00087   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
<a name="l00088"></a>00088   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
<a name="l00089"></a>00089   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
<a name="l00090"></a>00090 };
<a name="l00091"></a>00091 
<a name="l00092"></a>00092 
<a name="l00097"></a><a class="code" href="group__cherry8x16__example.html#gab94a7d38d92cefba725521d954ede75a">00097</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__cherry8x16__example.html#gab94a7d38d92cefba725521d954ede75a">uart_puthidstring</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *str)
<a name="l00098"></a>00098 {
<a name="l00099"></a>00099   uint_fast8_t i = 0;
<a name="l00100"></a>00100   <span class="keywordtype">char</span> ch = str[i++];
<a name="l00101"></a>00101   <span class="keywordflow">while</span> (ch != <span class="charliteral">&#39;\0&#39;</span>)
<a name="l00102"></a>00102   {
<a name="l00103"></a>00103     <a class="code" href="group__nrf__drivers__simple__uart.html#ga6346f3ba3f0f1eaaa123064daa3df405">simple_uart_put</a>(usb_hid2_ascii_look_up[(uint8_t)ch]);
<a name="l00104"></a>00104     ch = str[i++];
<a name="l00105"></a>00105   }
<a name="l00106"></a>00106 }
<a name="l00107"></a>00107 <span class="preprocessor">#endif</span>
<a name="l00108"></a>00108 <span class="preprocessor"></span>
<a name="l00113"></a><a class="code" href="group__cherry8x16__example.html#ga840291bc02cba5474a4cb46a9b9566fe">00113</a> <span class="keywordtype">int</span> <a class="code" href="group__gpio__example.html#ga840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">void</span>)
<a name="l00114"></a>00114 {
<a name="l00115"></a>00115   <span class="keyword">const</span> uint8_t *key_packet;
<a name="l00116"></a>00116   uint8_t key_packet_size;
<a name="l00117"></a>00117 
<a name="l00118"></a>00118 <span class="preprocessor">#ifdef USE_UART</span>
<a name="l00119"></a>00119 <span class="preprocessor"></span>  <a class="code" href="group__nrf__drivers__simple__uart.html#ga15ab88a2172a5ea02ff41ae9711bc0af">simple_uart_config</a>(0, <a class="code" href="group__cherry8x16__example.html#gafb80f61fa944be28d9895a47602e8957">SIMPLE_UART_TXD_PIN_NUMBER</a>, 0, <a class="code" href="group__cherry8x16__example.html#ga93d696b159f34e012cf60f3c2e2050be">SIMPLE_UART_RXD_PIN_NUMBER</a>, <span class="keyword">false</span>); <span class="comment">// Hardware flow control not used in this example</span>
<a name="l00120"></a>00120 <span class="preprocessor">#else</span>
<a name="l00121"></a>00121 <span class="preprocessor"></span>  <span class="comment">// Configure pins 24-30 for LEDs, note that pin 31 is not connected</span>
<a name="l00122"></a>00122   <a class="code" href="group__nrf__gpio.html#ga08c820bf0360c7406b64ddaf3bfc7222" title="Configure GPIO pin range as outputs with normal drive strength. This function can be used to configur...">nrf_gpio_range_cfg_output</a>(24, 30);
<a name="l00123"></a>00123 <span class="preprocessor">#endif</span>
<a name="l00124"></a>00124 <span class="preprocessor"></span>
<a name="l00125"></a>00125   <span class="comment">// Enable pulldowns on row port, see matrix_row_port</span>
<a name="l00126"></a>00126   <a class="code" href="group__nrf__gpio.html#ga6d5c4a1b82ed45f7972aea6572e085f5" title="Configure GPIO pin range as inputs with given initial value set, hiding inner details. This function can be used to configure pin range as simple input.">nrf_gpio_range_cfg_input</a>(16, 23, <a class="code" href="group__nrf__gpio.html#gga07e0c8c0b30499cf0a7b79dbe62d3fcca314d4b349d7e59ea3373a1ced4f32e4d" title="Pin pulldown resistor enabled.">NRF_GPIO_PIN_PULLDOWN</a>);
<a name="l00127"></a>00127 
<a name="l00128"></a>00128   <span class="comment">// Column pin configuration, see matrix_column_port</span>
<a name="l00129"></a>00129   <a class="code" href="group__nrf__gpio.html#ga08c820bf0360c7406b64ddaf3bfc7222" title="Configure GPIO pin range as outputs with normal drive strength. This function can be used to configur...">nrf_gpio_range_cfg_output</a>(0, 15);
<a name="l00130"></a>00130 
<a name="l00131"></a>00131   <span class="keywordflow">if</span> (<a class="code" href="group__nrf__drivers__cherry8x16.html#ga4d88841d6f21173bb304d2bd41f67c91">cherry8x16_init</a>(<a class="code" href="group__cherry8x16__example.html#ga7b0771426bcb19acdebee8b36aed8824">matrix_row_port</a>, matrix_column_port, <a class="code" href="group__nrf__drivers__cherry8x16.html#gacb3e11a73fa9f827d1cb395d7474886b" title="If passed to cherry8x16_init, default lookup matrix will be used.">CHERRY8x16_DEFAULT_KEY_LOOKUP_MATRIX</a>) != <a class="code" href="group__nrf__drivers__cherry8x16.html#ggabb88a2cc8f85ba70003398a2e9e26a5ea7c38ac713571ced5641f27dc14091f8d">CHERRY8x16_OK</a>)
<a name="l00132"></a>00132   {
<a name="l00133"></a>00133 <span class="preprocessor">#ifdef USE_UART</span>
<a name="l00134"></a>00134 <span class="preprocessor"></span>    <a class="code" href="group__nrf__drivers__simple__uart.html#ga76e6bde269950e02affbff121c79d408">simple_uart_putstring</a>((<span class="keyword">const</span> uint8_t *)<span class="stringliteral">&quot;Init failed.&quot;</span>);
<a name="l00135"></a>00135 <span class="preprocessor">#else</span>
<a name="l00136"></a>00136 <span class="preprocessor"></span>    <a class="code" href="group__nrf__gpio.html#gac1d4940bc5ad4aad4f6363c7021b08ae" title="Write GPIO port.">nrf_gpio_port_write</a>(<a class="code" href="group__nrf__gpio.html#ggaa1a5c145e334817f2d960317d64fcb3da9075a015252fd02d27ba7ca897aa564d" title="Port 3 (GPIO pin 24-31)">NRF_GPIO_PORT_SELECT_PORT3</a>, 0x55);
<a name="l00137"></a>00137 <span class="preprocessor">#endif</span>
<a name="l00138"></a>00138 <span class="preprocessor"></span>    <span class="keywordflow">while</span> (<span class="keyword">true</span>) {}
<a name="l00139"></a>00139   }
<a name="l00140"></a>00140 
<a name="l00141"></a>00141   <span class="keywordflow">while</span>(<span class="keyword">true</span>)
<a name="l00142"></a>00142   {
<a name="l00143"></a>00143     <span class="keywordflow">if</span> (<a class="code" href="group__nrf__drivers__cherry8x16.html#ga0079fdc53514fc2c48f98779f0c24719">cherry8x16_new_packet</a>(&amp;key_packet, &amp;key_packet_size))
<a name="l00144"></a>00144     {
<a name="l00145"></a>00145 <span class="preprocessor">#ifdef USE_UART</span>
<a name="l00146"></a>00146 <span class="preprocessor"></span>      <span class="comment">// Send the whole key packet over UART</span>
<a name="l00147"></a>00147       <a class="code" href="group__cherry8x16__example.html#gab94a7d38d92cefba725521d954ede75a">uart_puthidstring</a>((<span class="keywordtype">char</span>*)&amp;key_packet[<a class="code" href="group__nrf__drivers__cherry8x16.html#gaa44734bdd788259bfec3a2d020b88ae5" title="Start index in the key packet where pressed keys are stored.">KEY_PACKET_KEY_INDEX</a>]);
<a name="l00148"></a>00148 <span class="preprocessor">#else</span>
<a name="l00149"></a>00149 <span class="preprocessor"></span>      <span class="comment">// Show modifier key state using the LEDs, ***NOTE*** LED&#39;s use GPIO pins from 8 to 15</span>
<a name="l00150"></a>00150       <a class="code" href="group__nrf__gpio.html#gac1d4940bc5ad4aad4f6363c7021b08ae" title="Write GPIO port.">nrf_gpio_port_write</a>(<a class="code" href="group__nrf__gpio.html#ggaa1a5c145e334817f2d960317d64fcb3da9075a015252fd02d27ba7ca897aa564d" title="Port 3 (GPIO pin 24-31)">NRF_GPIO_PORT_SELECT_PORT3</a>, key_packet[<a class="code" href="group__nrf__drivers__cherry8x16.html#ga41430f808d8d3b096877de667eb4d086" title="Index in the key packet where modifier keys such as ALT and Control are stored.">KEY_PACKET_MODIFIER_KEY_INDEX</a>]);
<a name="l00151"></a>00151 <span class="preprocessor">#endif</span>
<a name="l00152"></a>00152 <span class="preprocessor"></span>    }
<a name="l00153"></a>00153     nrf_delay_ms(25);
<a name="l00154"></a>00154   }
<a name="l00155"></a>00155 }
<a name="l00156"></a>00156 
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="nrf6310_2ext__sensors_2cherry8x16__example_2main_8c.html">main.c</a>      </li>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
      Copyright &copy 2006-2011 <a href="http://www.nordicsemi.no" style="text-decoration:none">Nordic Semiconductor</a>.
      All Rights Reserved.
      <a href="disclaimer.html">Disclaimer</a>
    </li>
   </ul>
 </div>


</body>
</html>
